Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit test api_version to enable api_version 2 #4785

Merged
merged 5 commits into from
Nov 2, 2023

Conversation

pwang200
Copy link
Contributor

This PR attempts to address the unit test api_version issues discussed in a previous PR #4568

  • the command line API still uses apiMaximumSupportedVersion.
  • the unit test RPCs will uses apiMinimumSupportedVersion if unspecified.

@@ -6403,7 +6403,7 @@ std::string
updateAPIVersionString(const char* const req)
{
static std::string version_str =
std::to_string(RPC::apiMaximumSupportedVersion);
std::to_string(RPC::apiMinimumSupportedVersion);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should minimum version be default or apiVersionIfUnspecified ? Both of them = 1 right now, so it doesn't really matter. But I am just curious.

Copy link
Collaborator

@arihantkothari arihantkothari Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know most of the times (maybe all the times), apiVersionIfUnspecified = apiMinimumSupportedVersion will be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot say no. I.e., probably make sense to use apiVersionIfUnspecified as default.

@@ -6403,7 +6403,7 @@ std::string
updateAPIVersionString(const char* const req)
{
static std::string version_str =
std::to_string(RPC::apiMaximumSupportedVersion);
std::to_string(RPC::apiMinimumSupportedVersion);
static auto place_holder = "%MAX_API_VER%";
Copy link
Collaborator

@arihantkothari arihantkothari Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are putting minimum version as version_str. Should this line instead be static auto place_holder = "%MIN_API_VER%"; ? [line 6407]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it back to RPC::apiMaximumSupportedVersion and we will see what we eventually decide to use as default. Could be apiVersionIfUnspecified as you said earlier.

@intelliot intelliot added this to the 2.0 milestone Oct 25, 2023
src/ripple/net/RPCCall.h Outdated Show resolved Hide resolved
@@ -1561,7 +1563,8 @@ rpcClient(
try
{
Json::Value jvRpc = Json::Value(Json::objectValue);
jvRequest = rpcCmdLineToJson(args, jvRpc, logs.journal("RPCParser"));
auto apiVersion = fromCmdLine? RPC::apiMaximumSupportedVersion : RPC::apiMinimumSupportedVersion;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not have this logic hardcoded in this location; it would be easier to understand if rpcClient took explicitly unsigned apiVersion parameter instead, and then fromCommandLine passes RPC::apiMaximumSupportedVersion. That maintains isolation of concerns and also enables unit tests to test different versions (by which, I mean more than two) of command line generated parameters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you go this way, I would add assert(apiVersion <= RPC::apiBetaVersion);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed.

@@ -1698,7 +1701,7 @@ fromCommandLine(
const std::vector<std::string>& vCmd,
Logs& logs)
{
auto const result = rpcClient(vCmd, config, logs);
auto const result = rpcClient(vCmd, config, logs, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned above, instead of true pass RPC::apiMaximumSupportedVersion here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@ximinez
Copy link
Collaborator

ximinez commented Oct 25, 2023

IMHO, this solution is backwards. When a new API version becomes officially supported, we want incompatible unit tests to break. That is a signal that they are version dependent and need to be updated to test all API versions (preferably), or a least updated to the latest API version.

@Bronek
Copy link
Collaborator

Bronek commented Oct 26, 2023

IMHO, this solution is backwards. When a new API version becomes officially supported, we want incompatible unit tests to break. That is a signal that they are version dependent and need to be updated to test all API versions (preferably), or a least updated to the latest API version.

Agree. Exposing apiVersion parameter, where appropriate, to unit tests, would make that easier.

@ximinez
Copy link
Collaborator

ximinez commented Oct 26, 2023

Agree. Exposing apiVersion parameter, where appropriate, to unit tests, would make that easier.

There's a helper function, forAllApiVersions for just this purpose.

@pwang200
Copy link
Contributor Author

pwang200 commented Oct 26, 2023

I kind of agree with what @ximinez said about "this solution is backwards". That could be the reason we had apiMaximumSupportedVersion as default. I changed the default back to apiMaximumSupportedVersion. (shows my (lack of) understanding of the issue.)

I addressed @Bronek comments. Now the apiVersion is unit tests' choice, instead of having to use what the command line use.

A bigger discussion is what should be used as unit test default. What @arihantkothari said (apiVersionIfUnspecified) also make sense in some cases.

@intelliot
Copy link
Collaborator

@pwang200 - from your perspective, is this PR ready for review + merge?

src/ripple/net/RPCCall.h Outdated Show resolved Hide resolved
@Bronek
Copy link
Collaborator

Bronek commented Oct 31, 2023

I addressed @Bronek comments. Now the apiVersion is unit tests' choice, instead of having to use what the command line use.

Now we can start using forAllApiVersions in unit tests for command line tests, as suggested by @ximinez, because with this change we have the ability to pass the API version down to rpcClient function.

Copy link
Collaborator

@Bronek Bronek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that's an overall improvement.


/** Internal invocation of RPC client.
* Used by both rippled command line as well as rippled unit tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this comment ! 👍

@@ -1698,7 +1672,8 @@ fromCommandLine(
const std::vector<std::string>& vCmd,
Logs& logs)
{
auto const result = rpcClient(vCmd, config, logs);
auto const result =
rpcClient(vCmd, config, logs, RPC::apiMaximumSupportedVersion);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this means that as soon as we bump apiMaximumSupportedVersion, the tx_history and ledger_header commands will stop working (as they are no longer recognized in API version 2). Ideally at this point we should remove them from parseCommand in this file (and also remove function RPCParser::parseTxHistory). This probably needs its own issue.

@pwang200
Copy link
Contributor Author

@pwang200 - from your perspective, is this PR ready for review + merge?

yes

Copy link
Collaborator

@seelabs seelabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This looks good. Approving as-is, but left two nits to consider. (I'm fine if the nits are not addressed).

rpcCmdToJson(
std::vector<std::string> const& args,
Json::Value& retParams,
beast::Journal j,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we make journal the last parameter.

std::vector<std::string> const& args,
Json::Value& retParams,
beast::Journal j,
unsigned int apiVersion);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not for this PR, but we should consider making apiVersion either an enum type with one enum per API version or maybe a strongly-typed int (int with a tag, like we do with base_uint).

Copy link
Collaborator

@arihantkothari arihantkothari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍

@intelliot intelliot requested a review from Bronek October 31, 2023 21:59
@intelliot
Copy link
Collaborator

re-requested review since a new commit was pushed after the last review.

Also, should we try to merge #4775 prior to this one?

@Bronek
Copy link
Collaborator

Bronek commented Nov 2, 2023

Also, should we try to merge #4775 prior to this one?

There's no need to delay this PR

@intelliot intelliot merged commit 056255e into XRPLF:develop Nov 2, 2023
16 checks passed
sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
The command line API still uses `apiMaximumSupportedVersion`.
The unit test RPCs use `apiMinimumSupportedVersion` if unspecified.

Context:
- XRPLF#4568
- XRPLF#4552
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants